package com.ohc.leetcode.数组;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 2022年6月18日16:25:16
 */
public class 组合总和39 {

    public static List<List<Integer>> combinationSum(int[] candidates, int target) {
        List<List<Integer>> lists = new ArrayList<>();
        Arrays.sort(candidates);
        int sum = 0;
        for (int i = 0; i < candidates.length; i++) {
            sum = 0;
            ArrayList<Integer> list = new ArrayList<>();
            for (int j = 0; j < candidates.length; j++) {
                sum += candidates[j];
                list.add(candidates[i]);
                if (sum == target) {
                    lists.add(list);
                    break;
                }
            }
        }
        return lists;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{2, 3, 6, 7};
        int target = 7;
        List<List<Integer>> lists = combinationSum(nums, target);
        System.out.println("lists = " + lists);
    }
}
